#ifndef BATTLESTATS_H_
#define BATTLESTATS_H_

#include "material.h"


#include <vector>

class CBattleAttackData
{
	
private:
	
	int m_ID;
	int m_MatID;
	
	int m_ThinkFuncID;
	
	std::string m_MenuText;
	std::string m_MoveText;
	
	int m_RepeatMin, m_RepeatMax;
	float m_DmgMinMul, m_DmgMaxMul;
	
	bool m_bStopQueue; //Determines if any moves can be done by any other enemy while this move is executing.
	
public:

	
	inline bool CanStopQueue()
	{
		
		return m_bStopQueue;
		
	}
	
	inline std::string GenerateMoveText( std::string name )
	{
		
		return ( name + m_MoveText );
		
	}
	
	inline int GenerateDamage( int str )
	{
		
		float dmgmin = m_DmgMinMul * 100.0f;
		float dmgmax = m_DmgMaxMul * 100.0f;
		
		if( ( int )dmgmin == ( int )dmgmax )
			return str * m_DmgMinMul;
		else
		{
			
			float d = ( float )Util::random( dmgmin, dmgmax ) * .01f;
			
			return str * d;
			
		}
		
	}
	
	inline int GenerateRepeatCount()
	{
		
		return ( m_RepeatMin == m_RepeatMax ) ? m_RepeatMin : Util::random( m_RepeatMin, m_RepeatMax );
		
	}
	
	inline int GetThinkFuncID()
	{
		
		return m_ThinkFuncID;
		
	}
	
	inline int GetID()
	{
		
		return m_ID;
		
	}
	
	inline void SetDamageRange( float min, float max )
	{
		
		m_DmgMinMul = min;
		m_DmgMaxMul = max;
		
	}
	
	inline void SetRepeatRange( int min, int max )
	{
		
		m_RepeatMin = min;
		m_RepeatMax = max;
		
	}
	
	inline std::string GetMenuText()
	{
		
		return m_MenuText;
		
	}
	
	inline void SetMenuText( std::string s )
	{
		
		m_MenuText = s;
		
	}
	
	inline void SetMoveText( std::string s )
	{
		
		m_MoveText = s;
		
	}
	
	inline void SetAnimID( int i )
	{
		
		m_MatID = i;
		
	}
	
	inline void SetID( int i )
	{
		
		m_ID = i;
		
	}
	
	inline void SetThinkFuncID( int i )
	{
		
		m_ThinkFuncID = i;
		
	}
	
};

class CBattleCharacterData
{
	
private:
	
	CSmartMap< int, CBattleAttackData > m_pAttacks;
	std::vector< CMaterial * > m_pSprites;
	std::string m_Name, m_NiceName;
	int m_Health, m_Power, m_Speed, m_Luck, m_Defense;
	float m_Scale;
	
	int m_LuaDataTable;
	
	std::map< int, CBattleAttackData * >::iterator m_AttackDataIter;
	
public:
	
	CBattleCharacterData() : m_Health( 0 ), m_Power( 0 ), m_Speed( 0 ), m_Luck( 0 ), m_Defense( 0 ), m_LuaDataTable( -1 )
	{
		
	}
	
	~CBattleCharacterData()
	{
		
		m_pAttacks.clear();
		
	}
	
	inline int GetLuaDataTable()
	{
		
		return m_LuaDataTable;
		
	}
	
	inline void SetLuaDataTable( int id )
	{
		
		m_LuaDataTable = id;
		
	}
	
	inline void IterateMoveList()
	{
		
		m_AttackDataIter = m_pAttacks.begin();
		
	}
	
	CBattleAttackData * NextMove()
	{
		
		if( m_AttackDataIter == m_pAttacks.end() )
			return NULL;
		
		CBattleAttackData * d = m_AttackDataIter->second;
		
		m_AttackDataIter++;
		
		return d;
		
	}
	
	inline CBattleAttackData * GetMove( int id )
	{
		
		return m_pAttacks.at( id );
		
	}
	
	inline void AddMove( int id, CBattleAttackData * ad )
	{
		
		m_pAttacks.set( id, ad );
		
	}
	
	inline void SetStats( int power, int def, int spd, int luck )
	{
		
		m_Power = power;
		m_Defense = def;
		m_Luck = luck;
		m_Speed = spd;
		
	}
	
	inline void SetScale( float f )
	{
		
		m_Scale = f;
		
	}
	
	inline float GetScale()
	{
		
		return m_Scale;
		
	}
	
	inline void AddSprite( CMaterial * m )
	{
		
		m_pSprites.push_back( m );
		
	}
	
	inline void SetNames( std::string n, std::string nn )
	{
		
		m_Name = n;
		m_NiceName = nn;
		
	}
	
	inline void SetHealth( int hp )
	{
		
		m_Health = hp;
		
	}
	
	inline const std::string & GetName()
	{
		
		return m_Name;
		
	}
	
	inline const std::string & GetNiceName()
	{
		
		return m_NiceName;
		
	}
	
	inline int GetHealth()
	{
		
		return m_Health;
		
	}
	
	inline int GetPower()
	{
		
		return m_Power;
		
	}
	
	inline int GetSpeed()
	{
		
		return m_Speed;
		
	}
	
	inline int GetSpriteCount()
	{
		
		return m_pSprites.size();
		
	}
	
	inline CMaterial * GetSprite( int i )
	{
		
		return m_pSprites[i];
		
	}

};

class CBattleStats
{

private:
	
	CSmartVector< CBattleCharacterData > m_BattleData;
	
public:
	
	inline CBattleCharacterData * GetBattleStats( std::string n )
	{
		
		for( std::vector< CBattleCharacterData * >::iterator iter = m_BattleData.begin();
			 iter != m_BattleData.end(); iter++ )
			{
				
				if( ( *iter )->GetName() == n )
					return ( *iter );
				
			}
			
		return NULL;
		
	}
	
	inline void AddStat( CBattleCharacterData * b )
	{
		
		m_BattleData.push_back( b );
	
	}
	
};

#endif
